<?php
/**
* @package      auto_occasion
* @subpackage   admin
* @author       CMS
* @copyright    2011
* @license      All rights reserved
*/

class BoParametreCtrl extends jController {

    
    public $pluginParams = array(
                                    '*'=>array('auth.required'=>true,
                                    'jacl2.right'=>'admin.compte.gerer'
                                    )
                            );


    /**
    * Affiche la page de liste des parametres
    */
    function index() {
        $rep = $this->getResponse('html');
        $rep->menusActifs = adminHtmlResponse::MENU_OPERATEURS ;

		$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jconfirmaction.jquery.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jconfirmaction.jquery.ask.js');


        jClasses::inc('admin~parametreSrv');
        $liste = parametreSrv::liste();

        $rep->bodyTpl = 'admin~BoParametreList';
        
        $rep->body->assign('liste', $liste);

        return $rep;
    }

    /**
    * Edition / ajout d'un parametre
    */
    function editer() {
        $rep = $this->getResponse('html');
        $rep->menusActifs = adminHtmlResponse::MENU_OPERATEURS ;
        
   		$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jquery.validation.js');

        jClasses::inc('commun~common');


        $id  = $this->param('param_id', '');

        $parametre   = ($id) ? common::chargeParId($id, 'ao_parametre') : common::init('ao_parametre');
        $parametre_localisation = common::liste('ao_parametre_location');

        $rep->body->assign('parametre', $parametre);
        $rep->body->assign('parametre_localisation', $parametre_localisation);

        $rep->bodyTpl = 'admin~BoParametreEdit';
        
        return $rep;
    }

    /**
    * Edition / ajout d'un pays interdit
    */
    function paysInterdit() {
        $rep = $this->getResponse('html');
        $rep->menusActifs = adminHtmlResponse::MENU_OPERATEURS ;
        
        $rep->addCSSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/css/jquery-ui.css');

		$rep->addCSSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/css/ui.multiselect.css');

        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jquery-ui.min.js');
		$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jquery.localisation-min.js');
		$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/ui.multiselect.js');

        jClasses::inc('commun~paysSrv');

        // liste des pays
        $liste = paysSrv::liste();

        // liste des pays interdits
        $interdit = paysSrv::interdit();

        $rep->body->assign('liste', $liste);
        $rep->body->assign('interdit', $interdit);

        $rep->bodyTpl = 'admin~BoPaysInterdit';
        
        return $rep;
    }



    /**
    * Sauvegarder un pays interdit
    */
    function savePaysInterdit() {
        $rep = $this->getResponse('redirect');
        
        jClasses::inc('commun~paysSrv');

        $pays = $this->param('pays', array());
        
        if (sizeof($pays)) {
            paysSrv::save($pays);
        }
        
        $rep->action = 'admin~BoParametre:paysInterdit';

        return $rep;
    }

    /**
    * Sauvegarder un parametre
    */
    function sauvegarder() {
        $rep = $this->getResponse('redirect');
        
        jClasses::inc('admin~parametreSrv');

        $parametre                  = new stdClass();
        $parametre->param_name      = $this->stringParam('param_name','');
        $parametre->param_location  = $this->intParam('categorie','');
        $parametre->param_content   = $this->param('param_value','');
        $parametre->param_status    = $this->intParam('status', 0);
        $parametre->param_id        = $this->intParam('id',0);

        if ($parametre->param_id) {
            parametreSrv::modifier($parametre);
        } else {
            parametreSrv::ajouter($parametre);
        }
        
        $rep->action = 'admin~BoParametre:index';

        return $rep;
    }

    /**
    * Supprime un parametre
    */
    function supprimer() {
        $rep = $this->getResponse('redirect');
        jClasses::inc('commun~common');

        $id = $this->stringParam('param_id');
        common::supprimer($id, 'ao_parametre');

        $rep->action = 'admin~BoParametre:index';

        return $rep;
    }

    /**
    * Edition / ajout de paramètres pour controle injection
    */
    function injection() {
        $rep = $this->getResponse('html');
        $rep->menusActifs = adminHtmlResponse::MENU_OPERATEURS ;
        
        $rep->addCSSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/css/jquery-ui.css');

		$rep->addCSSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/css/ui.multiselect.css');

        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jquery-ui.min.js');
		$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jquery.localisation-min.js');
		$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/ui.multiselect.js');

        jClasses::inc('commun~paysSrv');
        jClasses::inc('commun~injectionSrv');

        // liste des valeurs à contrôler
        $liste = injectionSrv::liste();

        $rep->body->assign('liste', $liste);

        $rep->bodyTpl = 'admin~BoControleInjection';
        
        return $rep;
    }


    /**
    * Edition / ajout d'un libellé injection
    */
    function editInjection() {
        $rep = $this->getResponse('html');
        $rep->menusActifs = adminHtmlResponse::MENU_OPERATEURS ;
        
   		$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jquery.validation.js');

        jClasses::inc('commun~common');


        $id  = $this->param('id', '');

        $injection   = ($id) ? common::chargeParId($id, 'ao_injection_names') : common::init('ao_injection_names');

        $rep->body->assign('injection', $injection);

        $rep->bodyTpl = 'admin~BoEditInjection';
        
        return $rep;
    }

        /**
    * Sauvegarder un parametre
    */
    function saveInjection() {
        $rep = $this->getResponse('redirect');
        
        jClasses::inc('commun~injectionSrv');

        $parametre                      = new stdClass();
        $parametre->libelle_injection   = $this->stringParam('libelle','');
        $parametre->id                  = $this->intParam('id','0');


        if ($parametre->id) {
            injectionSrv::modifier($parametre);
        } else {
            injectionSrv::ajouter($parametre);
        }
        
        $rep->action = 'admin~BoParametre:injection';

        return $rep;
    }


    /**
    * Supprime une injection
    */
    function supprInjection() {
        $rep = $this->getResponse('redirect');
        jClasses::inc('commun~common');

        $id = $this->stringParam('id');
        common::supprimer($id, 'ao_injection_names');

        $rep->action = 'admin~BoParametre:injection';

        return $rep;
    }



}